import {request} from '@inbiz/utils';
const version = InbizConfig.API_VERSION
import { formatListData } from '../../designer/wap/useListRequest';

// 删除模型数据
export async function deleteModelData({
  appId,
  modelKey,
  id,
}: {
  appId: string;
  modelKey: string;
  id: string;
}): Promise<boolean> {
  return request.post(
    `/inbiz/api/services/front/modelengine/v${version}/businessData/batchDeleteData`,
    {
      data: {
        appId,
        modelKey,
        recordIds: [id],
      },
    },
  );
}

// 获取通过recordId 获取模型单条数据  recordId 为查询器返回数据的id
export async function queryDataInfo(params: {
  appId: string;
  key: string;
  recordId: string;
  filterLazy: string;
}): Promise<{
  IsSuccess: boolean;
  Data?: {
    [key: string]: string | number | boolean | object | object[];
  };
}> {
  return request
    .post(`/inbiz/api/services/front/modelengine/v${version}/modelQueryAdapter/queryDataInfo`, {
      data: {
        ...params,
        appId: params.appId ? params.appId : params.appId || '',
      },
    })
    .then((res) => {
      if (res?.Data) {
        formatListData(res.Data);
      }
      return res;
    });
}
